package thread;


import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

// 继承Thread类
class Thread1 extends Thread {
    public void run() {
        System.out.println(Thread.currentThread().getName() + "(extends Thread) is running");
    }
}


// 实现Runnable接口
class Thread2 implements Runnable {
    public void run() {
        System.out.println(Thread.currentThread().getName() + "(implements Runnable) is running");
    }
}

// 实现Callable接口
class Thread3 implements Callable<String> {

    @Override
    public String call() throws Exception {
        return Thread.currentThread().getName() + "(implements Callable) is running";
    }
}

public class ThreadTest1 {

    void startSingleThread1() {
        Thread1 t1 = new Thread1();
        t1.start();
    }

    void startSingleThread2(){
        Thread2 t2 = new Thread2();
        Thread t = new Thread(t2);
        t.start();
    }

    void startSingleThread3() throws ExecutionException, InterruptedException {
        FutureTask<String> task = new FutureTask<>(new Thread3());
        Thread t = new Thread(task);
        t.start();
        String s = task.get();
        System.out.println(s);
    }


    public static void main(String[] args) {
        ThreadTest1 t = new ThreadTest1();
        t.startSingleThread1();
        t.startSingleThread2();
        try {
            t.startSingleThread3();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
